﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Database;

namespace Business
{
    public class QuanLyNguoiDung
    {
        TrungTamEntities TrungTam;

        public QuanLyNguoiDung(){
            TrungTam = new TrungTamEntities();
        }

        public List<NguoiDung> LayDanhSachNguoiDung()
        {
            var list = (from p in TrungTam.NguoiDungs
                        select p).ToList();
            return list;
        }

        public bool ThemNguoiDung(NguoiDung nguoidung)
        {
            try
            {
                TrungTam.AddToNguoiDungs(nguoidung);
                TrungTam.SaveChanges();
                return true;
            }
            catch (System.Exception ex)
            {
                return false;
            }
        }
        public bool XoaNguoiDung(String TaiKhoan){
            try
            {
                var nguoidung = (from p in TrungTam.NguoiDungs
                                 where p.TaiKhoan.Equals(TaiKhoan)
                                 select p).First();
                TrungTam.DeleteObject(nguoidung);
                TrungTam.SaveChanges();
                return true;
            }
            catch (System.Exception ex)
            {
                return false;
            }
        }

        public List<String> LayDanhSachTaiKhoan()
        {
            try
            {
                var list = (from p in TrungTam.NhanViens
                            where p.ChucVu.Equals("Giám Đốc") || p.ChucVu.Equals("Kế Toán")
                            select p.MaNV).ToList();
                return list;
            }
            catch (System.Exception ex)
            {
                return null;
            }
        }

        public NhanVien LayNhanVienTheoMa(String TaiKhoan){
            try
            {
                var nhanvien = (from p in TrungTam.NhanViens
                                where p.MaNV.Equals(TaiKhoan)
                                select p).FirstOrDefault();
                return nhanvien;
            }
            catch (System.Exception ex)
            {
                return null;
            }
        }
    }
}
